package com.zwps.biz.controller.http;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zwps.biz.api.model.dto.mointordentify.AlarmBroacdCastVO;
import com.zwps.biz.api.model.vo.pubpointall.*;
import com.zwps.biz.api.model.vo.pubwarnrec.CrossSectionCodeVO;
import com.zwps.biz.api.model.vo.pubwarnrec.CrossSectionVO;
import com.zwps.biz.api.model.vo.pubwarnrec.PubWarnRecVO;
import com.zwps.biz.api.model.vo.ststbprp.OtherPptnDateVO;
import com.zwps.biz.api.model.vo.ststbprp.OtherPptnPointDataVO;
import com.zwps.biz.api.model.vo.ststbprp.OtherPptnPointVO;
import com.zwps.biz.dal.db.object.AlarmBroadcastDO;
import com.zwps.biz.dal.db.object.PubWarnRec;
import com.zwps.biz.domain.service.AlarmBroadcastService;
import com.zwps.biz.domain.service.DsmPtrRecordService;
import com.zwps.biz.domain.service.PubPointAllService;
import com.zwps.biz.domain.service.PubWarnRecService;
import com.zwps.common.api.validator.IntOption;
import com.zwps.common.controller.response.message.ResponseDataMessage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author dzc
 * @date 2024/9/20 19:59
 * @description
 */


@RestController
@Validated
@RequestMapping("safety/gauging_point")
public class PubPointAllController {

    @Autowired
    private PubPointAllService  pubPointAllService;
    @Autowired
    private DsmPtrRecordService dsmPtrRecordService;

    @Autowired
    private PubWarnRecService warnRecService;
    @Autowired
    private AlarmBroadcastService alarmBroadcastService;
    @Tag(name = "安全监测")
    @Operation(summary = "测点录像地址")
    @GetMapping("video_url/{rscd}")
    String  getVideoURL(@Validated @NotBlank @PathVariable String rscd) {
        return pubPointAllService.getVideoURL(rscd);

    }
    @Tag(name = "安全监测")
    @Operation(summary = "测点测压管坐标及实时数据")
    @GetMapping("coordinate/{sttpcd}")
    List<PubPointAllVO> getAddress(@Validated @NotBlank @PathVariable String sttpcd ) {
        return pubPointAllService.getAddress(sttpcd);

    }
    @Tag(name = "安全监测")
    @Operation(summary = "获取未来3天预报信息折线图")
    @GetMapping("getForcastRainLineChartData")
    public ResponseDataMessage getForcastRainLineChartData(String nowTimes, HttpServletRequest request){
        String accessToken = request.getHeader("X-Access-Token");
        Map<String, Object> dataMap = pubPointAllService.queryForcastRainLineChartData(nowTimes, accessToken);
        return ResponseDataMessage.data(dataMap);
    }
    /**
     * 获取历史洪水演进过程
     * @param
     * @param
     * @return
     */
    @GetMapping("/getWDate")
    public ResponseDataMessage getWDate(@RequestParam(value = "id",required = false) String id){
        return ResponseDataMessage.data(pubPointAllService.getWDate(id));
    }

    /**
     * 获取历史洪水演进- 断面过程
     * @param
     * @param
     * @return
     */
    @GetMapping("/getSectionData")
    public ResponseDataMessage getSectionData(@RequestParam(value = "id",required = false) String id){
        return ResponseDataMessage.data(pubPointAllService.getSectionData(id));
    }

    /**
     * 根据类型获取测点状态
     */
    @GetMapping("countPointByType")
    public List<PubPointCountVO> countPointByType(@RequestParam(value = "type", required = false) String type) {
        return pubPointAllService.countPointByType(type);
    }


    /**
     * 获取水库概况详情
     *
     * @return
     */
    @GetMapping("getRsvrInfo")
    public RsvrInfoVO getRsvrInfo() {
        return pubPointAllService.getRsvrInfo();
    }

    /**
     * 获取获取档案信息
     */
    @GetMapping("/archives")
    public List<ArchivesVO> getArchives(@RequestParam(value = "id", required = false) String id) {
        return pubPointAllService.getArchives(id);
    }

    /**
     * 根据类型查测点信息
     */
    @GetMapping("/getPoinDate")
    public List<PubPointAllVO> getPoinDate(@RequestParam(value = "type" ,required = false) Integer type){
        return pubPointAllService.getPoinDate(type);
    }
    /**
     * 根据类型获取测点状态
     */
    @GetMapping("countPointByTypes")
    public List<PubPointCountVO> countPointByTypes(@RequestParam(value = "type", required = false) String type
                                                  ) {
        return pubPointAllService.countPointByTypes(type);
    }
    /**
       * 维养计划统计
     */
    @GetMapping("getMaintainInfo")
    public MaintainInfoVO getMaintainInfo(@RequestParam(value = "year", required = false) Integer year,
                                          @RequestParam(value = "projectType", required = false) String projectType) {
        return pubPointAllService.getMaintainInfo(year, projectType);
    }

    /**
     * 获取实时水位库容降雨量
     * @return
     */
    @GetMapping("getNowDateNew")
    public NowDateNewVO getNowDateNew() {
        return pubPointAllService.getNowDateNew();
    }
    /**
     * 获取实时水位库容降雨量
     * @return
     */
    @GetMapping("getLastPubWarnRec")
    public List<PubWarnRecVO> getLastPubWarnRec() {
        return warnRecService.getLastPubWarnRec();
    }

    /**
     * 巡检详情预览
     */
    @GetMapping("record/detail")
    public DsmPrtRecordDetailVO getRecordDetailById( Integer id) {
        return dsmPtrRecordService.getRecordDetailById(id);
    }
    /**
     * 获取杭埠河断面横断面数据
     * @return
     */
    @GetMapping("getCrossSectionList")
    public List<CrossSectionVO> getCrossSectionList(@RequestParam(value = "sccd",required = false)Integer sccd) {
        return pubPointAllService.getCrossSectionList(sccd);
    }

    /**
     * 获取杭埠河断面横断面
     * @return
     */
    @GetMapping("getCrossSectionCode")
    public List<CrossSectionCodeVO> getCrossSectionCode() {
        return pubPointAllService.getCrossSectionCode();
    }

    @GetMapping("getPubPointHistoryData")
    public List<PubSectionWarnVO> getPubPointHistoryData(@Valid @NotNull(message = "测站类型不能为空") Integer stationType,
                                                         @IntOption(value = {0, 1, 2}) @NotNull(message = "时间类型不能为空") Integer timeType,
                                                         String dataTime) {
        return pubPointAllService.getPubPointHistoryData(stationType, timeType, dataTime);
    }

    /**
     * 根据测点类型查询测点带最新值和异常状态
     *
     * @return
     */
    @GetMapping("getSectionAndValueByType")
    public List<PubSectionWarnVO> getSectionAndValueByType(@RequestParam(value = "type", required = false) Integer type) {
        return pubPointAllService.getSectionStutasByType(type, true);
    }

    /**
     * 查询水质检测记录
     *
     * @return
     */
    @GetMapping("getWaterQualityList")
    public List<WaterQualityVO> getWaterQualityList() {
        return pubPointAllService.getWaterQualityList();
    }


    /**
     * 查询雨量站信息
     */
    @GetMapping("getOhetrPptnPointList")
    public List<OtherPptnPointVO> getOthetrPptnPoint(@RequestParam(value = "type" ,defaultValue = "1") Integer type){
        return pubPointAllService.getOthetrPptnPoint(type);
    }

    /**
     * 根据雨量站编码查询雨量数据
     */
    @GetMapping("getOhetrPptnDate")
    public List<OtherPptnDateVO> getOhetrPptnDate(@RequestParam(value = "stcd") String stcd,
                                                  @RequestParam(value = "startTime",required = false)  String startTime,
                                                  @RequestParam(value = "endTime",required = false)  String endTime,
                                                  @RequestParam(value = "type" ,defaultValue = "0") Integer type,
                                                  @RequestParam(value = "code" ,defaultValue = "0") Integer code){
        return pubPointAllService.getOhetrPptnDate(stcd,startTime,endTime,type,code);
    }
    /**
     * 根据雨量站最新一条数据
     */
    @GetMapping("getOhetrPptnLastDate")
    public List<PubSectionWarnVO> getOhetrPptnLastDate(@RequestParam(value = "type" ,defaultValue = "0") Integer type ,@RequestParam(value = "code") Integer code){
        return pubPointAllService.getOhetrPptnLastDate(type,code);
    }

    /**
     * 查询电子围栏信息
     */
    @GetMapping("getElectronicCrawl")
    public List<PttnSectionVO> getElectronicCrawl(){
        return pubPointAllService.getElectronicCrawl();
    }

    /**
     * 查询雨量站历史数据信息
     */
    @GetMapping("getOhetrPptnPointDataList")
    public List<OtherPptnPointDataVO> getOhetrPptnPointDataList(@RequestParam(value = "type",required = false) Integer type,
                                                                @RequestParam("stcd") String stcd,
                                                                @RequestParam(value = "startTime",required = false) String startTime,
                                                                @RequestParam(value = "endTime",required = false) String endTime){
        return pubPointAllService.getOhetrPptnPointDataList(type,stcd,startTime,endTime);
    }
    @GetMapping("getAlarmBroadCastList")
    public IPage<AlarmBroadcastDO> getAlarmBroadCastList(@RequestParam(value = "startTime",required = false) String startTime,
                                                         @RequestParam(value = "endTime" ,required = false) String endTime,
                                                         @RequestParam(defaultValue = "1") Integer pageNum,
                                                         @RequestParam(defaultValue = "10") Integer pageSize){
        return alarmBroadcastService.getAlarmBroadCastList(startTime,endTime ,pageNum,pageSize);
    }
    @GetMapping("getWaterFile")
    public ResponseDataMessage getWaterFile(){
        return  ResponseDataMessage.data(pubPointAllService.getWaterFile());
    }
}
